home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / trackldr1_43.lha / Trackloader1_43.asm
Assembly Source File  |  1994-08-16  |  17KB  |  654 lines

  1. *************************************************************************
  2. *                                    *
  3. *                 Trackloader coded by Patrik Lundquist                 *
  4. *                                    *
  5. *                              Version 1.43                *
  6. *                                    *
  7. *               Copyright (c) 1991-94 by Patrik Lundquist               *
  8. *                                    *
  9. *                                    *
  10. * I coded this loader back in 1991 and fixed a bug in May `93, when I    *
  11. * also released version, 1.0. Since people have shown interest I    *
  12. * thought I'd better release a newer vesion.                *
  13. *                                    *
  14. * The loader accepts blocks in the range of 0-1803 (cylinders 0-81).    *
  15. * I wouldn't recommend using cylinders 80-81 as it's not standard.    *
  16. * You should have this loader running outside your interrupts.        *
  17. * Registers d0-d7/a0-a2 are trashed by Loader.                *
  18. *                                    *
  19. * These registers are initialized in LoaderInit:            *
  20. *            lea $bfd000,a3                    *
  21. *            lea LDR_vars,a4                    *
  22. *            lea $dff000,a5                    *
  23. *                                    *
  24. * LoaderInit:                                *
  25. * description:    Initializes registers, variables and drives.        *
  26. *    requires:    nothing                            *
  27. *    input:    d0.b    - retries, 0-255                *
  28. *      result:    none                            *
  29. *                                    *
  30. * LoaderExit:                                *
  31. * description:    Cleans up. Restores registers.                *
  32. *    requires:    lea $bfd000,a3  --  doesn't trash any reg        *
  33. *        lea LDR_vars,a4                        *
  34. *        lea $dff000,a5                        *
  35. *    input:    none                            *
  36. *      result:    none                            *
  37. *                                    *
  38. * Loader:                                *
  39. * description:    Loads from disk.                    *
  40. *    requires:    lea $bfd000,a3                        *
  41. *        lea LDR_vars,a4                        *
  42. *        lea $dff000,a5                        *
  43. *    input:    d0.l    - startblock, 0-1803                *
  44. *        d1.l    - blocks to read, 1-1804            *
  45. *        d2.b    - drive to use, 0-3                *
  46. *        a0    - destination address                *
  47. *      result:    d0.l    -  0 = Success                    *
  48. *              -1 = Out of boundary sector read        *
  49. *              -2 = Drive not available            *
  50. *              -3 = No disk in drive                *
  51. *              -4 = Sync not found                *
  52. *              -5 = Checksum error                *
  53. *                                    *
  54. * LoaderUpdate:                                *
  55. * description:    Updates information about inserted disks, DRV_Status.    *
  56. *    requires:    lea $bfd000,a3  --  doesn't trash any reg        *
  57. *    input:    none                            *
  58. *      result:    none                            *
  59. *                                    *
  60. * About    LDR_DriveX's DRV_Status:                    *
  61. *  Bit set = true.    0  -  Drive available                *
  62. *            1  -  Disk inserted                *
  63. *            2-7   Unused                    *
  64. *                                    *
  65. *                                    *
  66. * You may use this source partly or in whole for non commercial and    *
  67. * non destructive purposes. I would appreciate credits if you use it.    *
  68. * Think twice before you decide to use a trackloader, most people    *
  69. * have a harddisk nowadays!                        *
  70. *                                    *
  71. * This sourcecode may not be distributed for profit.            *
  72. *                                    *
  73. * This sourcecode is provided "AS IS" without warranty of any kind,    *
  74. * either expressed or implied. By using this source you agree to accept    *
  75. * the entire risk as to the quality and performance of the source.    *
  76. * I can NOT be held liable for any damaged caused by this sourcecode.    *
  77. *                                    *
  78. * Changes in version 1.1:                        *
  79. *   - Code cleaning, optimizations.                    *
  80. *   - Multiple drives supported.                    *
  81. *                                    *
  82. * Changes in version 1.2:                        *
  83. *   - Data checksum error check.                    *
  84. *   - Retries.                                *
  85. *                                    *
  86. * Changes in version 1.3:                        *
  87. *   - Checks for inserted disks.                    *
  88. *                                    *
  89. * Changes in version 1.4:                        *
  90. *   - Minor improvements.                        *
  91. *                                    *
  92. * Changes in version 1.41:                        *
  93. *   - Much faster checksum calculation.                    *
  94. *                                    *
  95. * Changes in version 1.42:                        *
  96. *   - More automatic disk checking.                    *
  97. *                                    *
  98. * Changes in version 1.43:                        *
  99. *   - Error codes.                            *
  100. *                                    *
  101. * You can reach me here:                        *
  102. *                                    *
  103. * Internet:    pi92plu@pt.hk-r.se                    *
  104. *                                    *
  105. * IRC:        PatrikL @ #amiga                    *
  106. *                                    *
  107. *************************************************************************
  108.  
  109.         include    hardware/cia.i
  110.  
  111.         Section    Demonstration,Code
  112.         Opt    c+,o+,ow2-,u-
  113.  
  114. DemoStart    lea    $dff000,a5
  115.  
  116.         move.w    $1c(a5),oldintena    save old interrupt enable
  117.         bset    #7,oldintena
  118.         move.w    $1e(a5),oldintreq    save old interrupt request
  119.         bset    #7,oldintreq
  120.  
  121.         move.w    #$7fff,d1
  122.         move.w    d1,$9a(a5)        kill all interrupts
  123.         move.w    d1,$9c(a5)
  124.  
  125.         moveq    #3,d0            Retries, 0-255
  126.         jsr    LoaderInit        Setup loader.
  127.  
  128.         move.l    #880,d0            Start block, 0-1803
  129.         moveq    #88,d1            Blocks to read, 1-1804
  130.         move.b    #0,d2            Drive 0, 0-3
  131.         lea    DestBuffer,a0        Destination address
  132.         jsr    Loader
  133.         tst.l    d0
  134.         bne.s    Failure
  135.  
  136.         moveq    #0,d0            Start block, 0-1803
  137.         moveq    #88,d1            Blocks to read, 1-1804
  138.         move.b    #0,d2            Drive 0, 0-3
  139.         lea    DestBuffer,a0        Destination address
  140.         jsr    Loader
  141.         tst.l    d0
  142.         bne.s    Failure
  143.  
  144.         move.l    #1600,d0        Start block, 0-1803.
  145.         moveq    #88,d1            Blocks to read, 1-1804
  146.         move.b    #1,d2            Drive 1, 0-3
  147.         lea    DestBuffer,a0        Destination address
  148.         jsr    Loader
  149.         tst.l    d0
  150.         bne.s    Failure
  151.  
  152. DemoExit    jsr    LoaderExit        Restore hardware registers.
  153.         move.w    oldintena(pc),$9a(a5)
  154.         move.w    oldintreq(pc),$9c(a5)
  155.         rts
  156.  
  157. Failure        MOVE.W    #$F00,$180(A5)
  158.         bra.s    DemoExit
  159.  
  160. oldintena    ds.w    1
  161. oldintreq    ds.w    1
  162.  
  163. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  164.  
  165.         Section    DemoDest,BSS
  166.  
  167. DestBuffer    ds.b    88*512        88 blocks, only for demonstration.
  168.  
  169. *===========================================================================*
  170.  
  171.         Section    Trackloader,Code
  172.         Opt    c+,o+
  173.  
  174.     *    Retries -> d0.b
  175.  
  176. ldr_SyncWord    equ    $4489
  177.  
  178. LoaderInit    lea    $bfd000,a3
  179.         lea    LDR_vars(pc),a4
  180.         lea    $dff000,a5
  181.  
  182.         move.b    ciacra(a3),LDR_oldCRA(a4)
  183.         move.w    $10(a5),LDR_oldADK(a4)
  184.         bset    #7,LDR_oldADK(a4)
  185.         and.w    #$9500,LDR_oldADK(a4)
  186.         move.w    $2(a5),LDR_oldDMA(a4)
  187.         bset    #7,LDR_oldDMA(a4)
  188.         and.w    #$8210,LDR_oldDMA(a4)
  189.  
  190.         move.w    #ldr_SyncWord,$7e(a5)    DSKSYNC
  191.         move.w    #$9500,$9e(a5)        ADKCON
  192.         move.w    #$4000,$24(a5)        dsklen, disk DMA off
  193.         move.w    #$8210,$96(a5)        Disk DMA
  194.     move.b    #CIACRAF_OUTMODE!CIACRAF_RUNMODE!CIACRAF_SPMODE,ciacra(a3)    Stop, one-shot mode.
  195.  
  196.         move.b    d0,LDR_Retries(a4)
  197.  
  198. ; Find available drives and init them. DF0: is assumed to always be available.
  199. ; Can't get an ID stream from DF0: DD drives anyway.
  200.  
  201.         move.b    #3,LDR_Drive(a4)    DF0:
  202.         lea    LDR_Drive0(pc),a2
  203.         bset    #0,DRV_Status(a2)
  204.         bsr    ldr_GoToCyl0
  205.  
  206.         lea    DRV_SIZEOF(a2),a2
  207.         move.b    #4,d3            DF1:
  208.         move.b    #%00001000,d4        DF0:
  209.         move.w    #2,d2
  210. .driveLoop    move.b    d3,LDR_Drive(a4)
  211.         bsr    ldr_MotorOn        Reset serial shifter
  212.         bsr    ldr_MotorOff        by turning motor on and off
  213.         moveq    #0,d5
  214.         move.w    #31,d1
  215. .nextBit    bclr    d3,ciaprb(a3)        Select drive
  216.         btst    #CIAB_DSKRDY,$bfe001
  217.         bne.s    .bitClear        Active when low
  218.         bset    d1,d5            Collect serial bits in d5
  219. .bitClear    bset    d3,ciaprb(a3)        Deselect drive
  220.         dbra    d1,.nextBit
  221.         cmp.l    #-1,d5
  222.         bne.s    .noDrive
  223.         bset    d3,d4
  224.         bset    #0,DRV_Status(a2)
  225.         bsr    ldr_GoToCyl0
  226. .noDrive    addq.b    #1,d3
  227.         lea    DRV_SIZEOF(a2),a2
  228.         dbra    d2,.driveLoop
  229.         move.b    d4,LDR_DrivesAvail(a4)
  230.  
  231.         bsr.s    LoaderUpdate
  232.         rts
  233.  
  234. *­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­*
  235.  
  236. LoaderExit    move.b    LDR_oldCRA(a4),ciacra(a3)
  237.         move.w    #$1500,$9e(a5)
  238.         move.w    LDR_oldADK(a4),$9e(a5)
  239.         move.w    #$0210,$96(a5)
  240.         move.w    LDR_oldDMA(a4),$96(a5)
  241.         rts
  242.  
  243. *­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­*
  244.  
  245. LoaderUpdate    movem.l    a2/d2-3,-(sp)
  246.         moveq    #3,d2
  247.         move.b    d2,d3
  248.         lea    LDR_Drive0(pc),a2
  249. .loop        btst    #0,DRV_Status(a2)
  250.         beq.s    .noUnit
  251.         or.b    #$78,ciaprb(a3)        Deselect all drives
  252.         bclr    d3,ciaprb(a3)        Select drive
  253.         btst    #0,DRV_CylPos(a2)
  254.         beq.s    .even
  255.         bsr    ldr_MoveOut
  256.         bra.s    .test
  257. .even        bsr    ldr_MoveIn        
  258. .test        bclr    #1,DRV_Status(a2)
  259.         btst    #CIAB_DSKCHANGE,$bfe001
  260.         beq.s    .noDisk
  261.         bset    #1,DRV_Status(a2)
  262. .noDisk
  263. .noUnit        lea    DRV_SIZEOF(a2),a2
  264.         addq.b    #1,d3
  265.         dbra    d2,.loop
  266.         or.b    #$78,ciaprb(a3)        Deselect all drives
  267.         movem.l    (sp)+,a2/d2-3
  268.         rts
  269.  
  270. *­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­*
  271.  
  272.     *    Control routine.
  273.  
  274.     *    Start block -> d0.l
  275.     *    Number of blocks -> d1.l
  276.     *    Drive to use -> d2.b
  277.     *    Destination address -> a0
  278.  
  279.     * Returns success in d0
  280.  
  281. ; What a mess...
  282.  
  283. Loader        tst.w    d1
  284.         beq    .QuitLoader
  285.         move.l    d0,d3
  286.         add.w    d1,d0
  287.         cmp.w    #1804,d0
  288.         ble.s    .okSectorRange
  289.         moveq    #-1,d0        Out of boundary sector read
  290.         rts
  291.  
  292. .okSectorRange    lea    LDR_Drive0(pc),a2
  293.         cmp.b    #0,d2
  294.         beq.s    .rightUnit
  295.         lea    DRV_SIZEOF(a2),a2
  296.         cmp.b    #1,d2
  297.         beq.s    .rightUnit
  298.         lea    DRV_SIZEOF(a2),a2
  299.         cmp.b    #2,d2
  300.         beq.s    .rightUnit
  301.         lea    DRV_SIZEOF(a2),a2
  302.         cmp.b    #3,d2
  303.         beq.s    .rightUnit
  304.         moveq    #-2,d0        Drive not available
  305.         rts
  306.  
  307. .rightUnit    addq.b    #3,d2
  308.         moveq    #0,d0
  309.         bset    d2,d0
  310.         and.b    LDR_DrivesAvail(a4),d0
  311.         bne.s    .driveExists
  312.         moveq    #-2,d0        Drive not available
  313.         rts
  314.  
  315. .driveExists    move.b    d2,LDR_Drive(a4)
  316.         bsr    LoaderUpdate
  317.         btst    #1,DRV_Status(a2)    Any disk?
  318.         bne.s    .diskInserted
  319.         moveq    #-3,d0        No disk in drive
  320.         rts
  321.  
  322. .diskInserted    bsr    ldr_MotorOn
  323.         divu.w    #11,d3
  324.         move.b    d3,LDR_StartTrk(a4)
  325.         swap     d3
  326.         move.b    d3,LDR_StartSec(a4)
  327.         add.w    d3,d1
  328.         swap    d3
  329.         subq.w    #1,d1            End block
  330.         divu.w    #11,d1
  331.         move.b    d1,LDR_Tracks(a4)
  332.         swap     d1
  333.         addq.w    #1,d1
  334.         move.b    d1,LDR_EndSec(a4)    Amount of sectors to read on last track
  335.  
  336.  
  337.         move.b    d3,d1            Start-track in d3.
  338.         move.b    DRV_CylPos(a2),d2
  339.         lsr.b    #1,d1
  340.         cmp.b    d1,d2
  341.         beq.s    .RightCyl        No need to move head.
  342.         blt.s    .MoveInwards
  343.         sub.b    d1,d2            Moving heads outwards.
  344.         bsr    ldr_MoveOut
  345.         subq.b    #1,d2
  346.         beq.s    .RightCyl
  347.         subq.b    #1,d2
  348.         ext.w    d2
  349. .MoveHeadOut    bsr    ldr_MoveHead
  350.         dbra    d2,.MoveHeadOut
  351.         bra.s    .RightCyl
  352.  
  353. .MoveInwards    sub.b    d2,d1            Moving heads inwards.
  354.         bsr    ldr_MoveIn
  355.         subq.b    #1,d1
  356.         beq.s    .RightCyl
  357.         subq.b    #1,d1
  358.         ext.w    d1
  359. .MoveHeadIn    bsr    ldr_MoveHead
  360.         dbra    d1,.MoveHeadIn
  361. .RightCyl    btst    #0,LDR_StartTrk(a4)        Time to pick side.
  362.         beq.s    .LowerIt
  363.         btst    #CIAB_DSKSIDE,ciaprb(a3)
  364.         beq.s    .RightTrack
  365.         bsr    ldr_Upper
  366.         bra.s    .RightTrack
  367.  
  368. .LowerIt    btst    #CIAB_DSKSIDE,ciaprb(a3)
  369.         bne.s    .RightTrack
  370.         bsr    ldr_Lower
  371. .RightTrack    move.b    LDR_StartSec(a4),d3    And now, the reading begins.
  372.         move.b    LDR_Tracks(a4),d2
  373.         beq.s    .LastTrack
  374.         moveq    #11,d4
  375.         bsr.s    ldr_Read
  376.         tst.l    d0
  377.         bne.s    .LoaderFail
  378. .NextTrack    moveq    #0,d3
  379.         btst    #CIAB_DSKSIDE,ciaprb(a3)
  380.         bne.s    .NextSide
  381.         bsr    ldr_Lower
  382.         btst    #CIAB_DSKDIREC,ciaprb(a3)
  383.         bne.s    .FirstMoveIn
  384.         bsr    ldr_MoveHead
  385.         bra.s    .NextRead
  386.  
  387. .FirstMoveIn    bsr    ldr_MoveIn
  388.         bra.s    .NextRead
  389.  
  390. .NextSide    bsr    ldr_Upper
  391. .NextRead    subq.b    #1,d2
  392.         beq.s    .LastTrack
  393.         bsr.s    ldr_Read
  394.         tst.l    d0
  395.         bne.s    .LoaderFail
  396.         bra.s    .NextTrack
  397.  
  398. .LastTrack    move.b    LDR_EndSec(a4),d4
  399.         bsr.s    ldr_Read
  400.         tst.l    d0
  401.         bne.s    .LoaderFail
  402.         bsr.s    ldr_MotorOff
  403. .QuitLoader    moveq    #0,d0
  404.         rts
  405.  
  406. .LoaderFail    bsr.s    ldr_MotorOff
  407.         rts
  408.  
  409. *===========================================================================*
  410.  
  411. ldr_MotorOn    move.b    LDR_Drive(a4),d0
  412.         or.b    #$78,ciaprb(a3)    Set bits 3,4,5 and 6,
  413.                 ;    deselect all drives.
  414.         bclr    #CIAB_DSKMOTOR,ciaprb(a3)    Switch on motor.
  415.         bclr    d0,ciaprb(a3)    Clear drive bit.
  416.         rts
  417.  
  418. *­---------------------------------------------­*
  419.  
  420. ldr_MotorOff    move.b    LDR_Drive(a4),d0
  421.         or.b    #$f8,ciaprb(a3)    Set bits 3,4,5,6 and 7,
  422.                 ;    deselects all drives, motor off.
  423.         bclr    d0,ciaprb(a3)    Clear drive bit.
  424.         rts
  425.  
  426. *­---------------------------------------------­*
  427.  
  428. ldr_Read    move.b    LDR_Retries(a4),d5
  429.         moveq    #0,d6
  430. .reRead        move.b    #$91,ciatalo(a3)        Timer A low.
  431.         move.b    #$29,ciatahi(a3)        Timer A hi, and starts timer.
  432. .DSKRDY        btst    #CIAB_DSKRDY,$bfe001    Await Disk ready.
  433.         bne.s    .DSKRDY
  434.         bsr    ldr_Timer
  435.         move.w    #2,$9c(a5)        Clear Disk Int. request.
  436.         move.l    #ldr_TrackBuffer,$20(a5)    DSKPT, MFM-buffer.
  437.         move.w    #$9900,$24(a5)        dsklen, read lenght.
  438.         move.w    #$9900,$24(a5)        dsklen
  439. .DMAwait    btst    #1,$1f(a5)        DMA transfer done when high.
  440.         beq.s    .DMAwait    Imagine a sync is never found... Deadlock! :-)
  441.         move.w    #$4000,$24(a5)        Disk DMA off.
  442.  
  443.         bsr.s    ldr_Decode
  444.         tst.l    d0
  445.         bne.s    .error
  446.         rts
  447. .error
  448.         addq.b    #1,d6
  449.         cmp.b    d6,d5
  450.         bhs.s    .reRead
  451.         rts
  452.  
  453. *­---------------------------------------------­*
  454.     *    Destination address -> a0
  455.     *    Start sector -> d3
  456.     *    End sector -> d4
  457.  
  458. ; In case of failure ldr_Decode only tries to decode what's left from last
  459. ; try.
  460.  
  461. ldr_Decode    movem.l    d2/d5-7/a1-2,-(sp)
  462.         move.l    #$55555555,d7        %010101...
  463.  
  464. .FindSector    lea    ldr_TrackBuffer,a1
  465.         move.l    #ldr_TrackBuffer+$3200-$440,d2
  466.         move.w    #ldr_SyncWord,d5    Sync-word.
  467. .SyncSearch    cmp.l    d2,a1            Check if within track buffer
  468.         ble.s    .withinBuffer
  469.         moveq    #-4,d0            Sync not found
  470.         bra.s    .DecodeFail
  471.  
  472. .withinBuffer    cmp.w    (a1)+,d5        Check for Sync-word.
  473.         bne.s    .SyncSearch
  474.         cmp.w    (a1),d5            Another Sync-word?
  475.         beq.s    .SyncSearch
  476.         move.l    (a1)+,d0        Get sector we're looking at
  477.         move.l    (a1),d1
  478.         and.w    d7,d0
  479.         add.w    d0,d0    ; lsl.w    #1,d0
  480.         and.w    d7,d1
  481.         or.w    d1,d0
  482.         lsr.w    #8,d0
  483.         cmp.b    d3,d0            Correct sector?
  484.         beq.s    .CorrectSctr
  485.         lea    $43a(a1),a1    Move to next sector, 2nd sync word.
  486.         bra.s    .SyncSearch
  487.  
  488. .CorrectSctr    lea    $30(a1),a1        Skip to Data checksum
  489.         move.l    (a1)+,d6        Get Data-block checksum
  490.         and.l    d7,d6
  491.  
  492.         moveq    #$7f,d2
  493.         lea    $200(a1),a2
  494.         moveq    #0,d5
  495. .DeCodeLoop    move.l    (a1)+,d0
  496.         and.l    d7,d0
  497.         add.l    d0,d0    ; lsl.l    #1,d0
  498.         move.l    (a2)+,d1
  499.         and.l    d7,d1
  500.         or.l    d1,d0
  501.         move.l    d0,(a0)+        Move to Load Address.
  502.         eor.l    d0,d5
  503.         dbra    d2,.DeCodeLoop
  504.  
  505.         move.l    d5,d1            Checksum control
  506.         lsr.l    #1,d1
  507.         eor.l    d1,d5
  508.         and.l    d7,d5
  509.         cmp.l    d5,d6
  510.         beq.s    .chksumOk
  511.         lea    -512(a0),a0        Step back faulty sector
  512.         moveq    #-5,d0            Checksum error
  513. .DecodeFail    movem.l    (sp)+,d2/d5-7/a1-2
  514.         rts
  515.  
  516. .chksumOk    addq.b    #1,d3            Add sector we just processed
  517.         cmp.b    d4,d3
  518.         bne.s    .FindSector
  519.         movem.l    (sp)+,d2/d5-7/a1-2
  520.         moveq    #0,d0
  521.         rts
  522.  
  523. *­---------------------------------------------­*
  524.  
  525. ldr_GoToCyl0    move.b    LDR_Drive(a4),d0
  526.         or.b    #$78,ciaprb(a3)        Deselect all drives
  527.         bclr    d0,ciaprb(a3)        Select drive
  528.         btst    #CIAB_DSKTRACK0,$bfe001    Cyl 0 when low.
  529.         beq.s    .AtCylPos0
  530.         bsr.s    ldr_MoveOut
  531. .TowardsCyl0    btst    #CIAB_DSKTRACK0,$bfe001    Cyl 0 when low.
  532.         beq.s    .AtCylPos0
  533.         bclr    #CIAB_DSKSTEP,ciaprb(a3)    Move head.
  534.         bset    #CIAB_DSKSTEP,ciaprb(a3)    Prepare to move head.
  535.         move.b    #$15,ciatalo(a3)    Timer A low.
  536.         move.b    #$0b,ciatahi(a3)    Timer A hi, and starts timer.
  537.         bsr    ldr_Timer        4ms
  538.         bra.s    .TowardsCyl0
  539.  
  540. .AtCylPos0    clr.b    DRV_CylPos(a2)
  541.         or.b    #$78,ciaprb(a3)        Deselect all drives
  542.         rts
  543.  
  544. *­---------------------------------------------­*
  545.  
  546. ldr_Upper    bclr    #CIAB_DSKSIDE,ciaprb(a3)    Upper side.
  547.         move.b    #$47,ciatalo(a3)    Timer A low.
  548.         clr.b    ciatahi(a3)    Timer A hi, and starts timer.
  549.         bra    ldr_Timer    100µs
  550.  
  551. *­---------------------------------------------­*
  552.  
  553. ldr_Lower    bset    #CIAB_DSKSIDE,ciaprb(a3)    Lower side.
  554.         move.b    #$47,ciatalo(a3)    Timer A low.
  555.         clr.b    ciatahi(a3)    Timer A hi, and starts timer.
  556.         bra.s    ldr_Timer    100µs
  557.  
  558. *­---------------------------------------------­*
  559.  
  560. ldr_MoveOut    bset    #CIAB_DSKDIREC,ciaprb(a3)    Head direction outwards.
  561.         bclr    #CIAB_DSKSTEP,ciaprb(a3)    Move head.
  562.         bset    #CIAB_DSKSTEP,ciaprb(a3)    Prepare to move head.
  563.         move.b    #$e1,ciatalo(a3)    Timer A low.
  564.         move.b    #$31,ciatahi(a3)    Timer A hi, and starts timer.
  565.         move.b    #-1,LDR_HeadDir(a4)
  566.         subq.b    #1,DRV_CylPos(a2)
  567.         bra.s    ldr_Timer    18ms
  568.  
  569. *­---------------------------------------------­*
  570.  
  571. ldr_MoveIn    and.b    #$fc,ciaprb(a3)    Clear bits 0 and 1,
  572.         ;    which results in diskdirec=inwards, head moved.
  573.         bset    #CIAB_DSKSTEP,ciaprb(a3)    Prepare to move head.
  574.         move.b    #$e1,ciatalo(a3)    Timer A low.
  575.         move.b    #$31,ciatahi(a3)    Timer A hi, and starts timer.
  576.         move.b    #1,LDR_HeadDir(a4)
  577.         addq.b    #1,DRV_CylPos(a2)
  578.         bra.s    ldr_Timer    18ms
  579.  
  580. *­---------------------------------------------­*
  581.  
  582. ldr_MoveHead    bclr    #CIAB_DSKSTEP,ciaprb(a3)    Move head.
  583.         bset    #CIAB_DSKSTEP,ciaprb(a3)    Prepare to move head.
  584.         move.b    #$50,ciatalo(a3)    Timer A low.
  585.         move.b    #$08,ciatahi(a3)    Timer A hi, and starts timer.
  586.         move.b    LDR_HeadDir(a4),d0
  587.         add.b    d0,DRV_CylPos(a2)
  588. ;        bra.s    ldr_Timer    3ms
  589.  
  590. *­---------------------------------------------­*
  591.  
  592. ldr_Timer    btst    #CIAICRB_TA,ciaicr(a3)    Await Timer ready.
  593.         beq.s    ldr_Timer
  594.         rts
  595.  
  596. *­---------------------------------------------­*
  597.  
  598.         RSRESET
  599.  
  600. LDR_oldADK    rs.w    1
  601. LDR_oldDMA    rs.w    1
  602. LDR_oldCRA    rs.b    1
  603.  
  604. LDR_HeadDir    rs.b    1
  605. LDR_StartTrk    rs.b    1
  606. LDR_StartSec    rs.b    1
  607. LDR_Tracks    rs.b    1
  608. LDR_EndSec    rs.b    1
  609. LDR_DrivesAvail    rs.b    1
  610. LDR_Drive    rs.b    1
  611. LDR_Retries    rs.b    1
  612. LDR_SIZEOF    rs.b    0
  613.  
  614. LDR_vars    ds.b    LDR_SIZEOF
  615.  
  616.  
  617.         RSRESET
  618.  
  619. DRV_CylPos    rs.b    1
  620. DRV_Status    rs.b    1
  621. DRV_SIZEOF    rs.b    0
  622.  
  623. LDR_Drive0    dcb.b    DRV_SIZEOF,0
  624. LDR_Drive1    dcb.b    DRV_SIZEOF,0
  625. LDR_Drive2    dcb.b    DRV_SIZEOF,0
  626. LDR_Drive3    dcb.b    DRV_SIZEOF,0
  627.  
  628. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  629.  
  630.         Section Track,BSS_C
  631.  
  632. ldr_TrackBuffer    ds.w    $1900        12800 bytes, room for one MFM-track.
  633.  
  634. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  635.  
  636.         End
  637.  
  638. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  639. Operation:                Wait Time:    Timervalue:
  640. ­­­­­­­­­                ­­­­­­­­­    ­­­­­­­­­­
  641.  Motor on                500ms, DSKRDY    $56982
  642.  Diskside stable before reading        100µs        $47
  643.  Diskside stable before writing        100µs        $47
  644.  Diskside stable after writing        1.3ms        $39A
  645.  Diskstep                3ms        $850
  646.  Reverse diskstep            18ms        $31E1
  647.  Settle time                15ms        $2991
  648.  Track 00 signal low after step        4ms        $B15
  649.  Track 00 signal hi after step        1µs        $1
  650.  Step after drive select        1µs        $1
  651.  Direction select before step        1µs        $1
  652.  Direction select after step        1µs        $1
  653.  Keep low signal            1µs        $1
  654.